<%@ page import="java.io.BufferedReader"%>
<%@ page import="java.io.FileReader"%>
<%@ page import="java.io.File"%>
<%@ page import="java.sql.*" %>
<%@ page import="java.util.*,bean.User" %>

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
    
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>用户分页查询</title>
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/csslect_css.css">
<style>
#a1{
	font-size:20px;
/* 	color:#a9bebc; */
	text-decoration:none;
	border:1px;
 	background-color:#00f0f0; 
	cursor:pointer;

}

</style>
</head>


<body>

<div class="wrapper">
		<div align="center" style="margin-top:30px;">
<!-- 			<span style="font-size:30px;">用户管理</span> -->
			
			<form action="${pageContext.request.contextPath}/SelectUser" method="post">
				<table align="center">
					<tr>
						<td><input type="text" name ="userName" size="30" placeholder="查询用户名" autocomplete="off" 
						style="width:190px;height:30px;border:1px solid black;border-radius:3px;font-size:16px;"></td>
<!-- 						<td><input type="text" name ="uname" size="30" placeholder="查询昵称" autocomplete="off"></td> -->
						<td><input type="text" name ="telephone" size="30" placeholder="查询电话" autocomplete="off" 
						style="width:190px;height:30px;border:1px solid black;border-radius:3px;font-size:16px;"></td>
						<td><button type="submit" style="width:80px;height:30px;border:1px solid black;border-radius:3px;background-color:#b9bcca;">查询</button></td>
					</tr>
				</table>
			</form>
		</div>
		
		<div class="select_frame" style="margin-top:30px;">
			<form >
				<table width="100%" style="height:10px;" id="table" cellpadding="0" cellspacing="0" align="center" border="0" >
					<tr  style="height:10px;">
						<td align="center" style="width:5%;height:40px;border:1px solid gray;border-radius:1px;">编号</td>
						<td align="center" style="width:10%;border:1px solid gray;">账号</td>
						<td align="center" style="width:10%;border:1px solid gray;">昵称</td>
						<td align="center" style="width:10%;border:1px solid gray;">真实姓名</td>
						<td align="center" style="width:7%;border:1px solid gray;">性别</td>
						
<!-- 						<td align="center" style="width:15%;border:1px solid gray;">邮箱</td> -->
<!-- 						<td align="center" style="width:15%;border:1px solid gray;">电话</td> -->
						
						<td align="center" style="width:10%;border:1px solid gray;">用户权限</td>
						<td align="center" style="width:30%;border:1px solid gray;">操作</td>
					</tr>
<!-- 				</table> -->
<!-- 				<table width="100%" align="center" cellpadding="0" cellspacing="0" id="table" style="margin:0 auto;"> -->
					<c:forEach var="it" items="${list }">
					
<%-- 					<input type="text" name="user_id" value="${it.user_id}" > --%>
					
						<tr height="50" align="center">
							<td style="width:3%;">${it.num}</td>
							<td style="width:10%;">${it.loginId}</td>
							<td style="width:10%;">${it.userName}</td>
							<td style="width:10%;">${it.realName}</td>
							
							<c:set var="gender"  value="${it.gender}"/>
								<c:if test="${gender == 0 }">
								<td style="width:10%;"><c:out value="男"/></td>
								</c:if>
								
								<c:if test="${gender == 1 }">
									<td style="width:10%;"><c:out value="女"/></td>
								</c:if>
								
<%-- 							<td style="width:10%;">${it.email}</td>	 --%>
<%-- 							<td style="width:10%;">${it.telephone}</td> --%>
							
							<c:set var="user_type"  value="${it.user_type}"/>
								<c:if test="${user_type == 0 }">
								<td style="width:10%;"><c:out value="普通用户"/></td>
								</c:if>
								
								<c:if test="${user_type == 1 }">
									<td style="width:10%;"><c:out value="管理员"/></td>
								</c:if>
							
							<td style="width:20%;">
								<table  cellspacing="20" cellpadding="0" >
									<td >
									<a href="${pageContext.request.contextPath}/Reset?id=${it.user_id}" style="text-decoration:none;"
									onclick="return confirm('确认重置“${it.userName} ”的密码为“888888”？');"><font size="4" color="#d9a5da">重置密码</font></a></td>
									
									<td><a href="${pageContext.request.contextPath}/Privilege?id=${it.user_id}" style="text-decoration:none;"
									onclick="return confirm('确认修改权限“${user.getUserName() }”？');"><font size="4px" color="#d9a5da">修改权限</font></a></td>
									
									<td><a href="${pageContext.request.contextPath}/Login_0615/detial.jsp?id=${it.loginId}" style="text-decoration:none;">
									<font size="4" color="#d9a5da">查看详情</font></a><td>
									
									<td><a href="${pageContext.request.contextPath}/Delete?id=${it.user_id}" style="text-decoration:none;"
									onclick="return confirm('确认删除“${user.getUserName() }”？');"><font size="5" color="#d9a5da">删除</font></a></td>
									
								</table>
							</td>
						</tr>
					</c:forEach>
				</table>
			</form>
			
			<div class="page_turn" style="margin-top:40px;">
			
				<form>
				<center>
					<span>共条</span>
					<span><a href="#" id="spanFirst">首页</a></span>
					<span><a href="#" id="spanPre">上一页</a></span>
					<span id="spanPageNum"></span>/<span id="spanTotalPage"></span>页
					<span><a href="#" id="spanNext">下一页</a></span>
					<span><a href="#" id="spanLast">尾页</a></span>
					<span><a href="${pageContext.request.contextPath}/user/home_page.jsp" target="right">【返回主页】</a></span>
				</center>
				</form>
				
			</div>
		</div>
	</div>
</body>

<script type="text/javascript">
	var theTable = document.getElementById("table");
	var totalPage = document.getElementById("spanTotalPage");
	var pageNum = document.getElementById("spanPageNum");
	var spanPre = document.getElementById("spanPre");
	var spanNext = document.getElementById("spanNext");
	var spanFirst = document.getElementById("spanFirst");
	var spanLast = document.getElementById("spanLast");
	var numberRowsInTable = theTable.rows.length;
	var pageSize = 10;//每一页条数
	var page = 1;//
	//下一页
	function next() {
		hideTable();
		currentRow = pageSize * page;
		maxRow = currentRow + pageSize;
		if ( maxRow > numberRowsInTable ){
			maxRow = numberRowsInTable;
		}
		for ( var i = currentRow; i < maxRow; i++ ) {
			theTable.rows[i].style.display = '';
		}
		page++;
		if ( maxRow == numberRowsInTable ){
			nextText();
			lastText();
		}
		showPage();
		preLink();
		firstLink();
	}
	//上一页
	function pre() {
		hideTable();
		page--;
		currentRow = pageSize * page;
		maxRow = currentRow - pageSize;
		if ( currentRow > numberRowsInTable )
		currentRow = numberRowsInTable;
		for ( var i = maxRow; i < currentRow; i++ ) {
			theTable.rows[i].style.display = '';
		}
		if ( maxRow == 0) {
			preText();
			firstText();
		}
		showPage();
		nextLink();
		lastLink();
	}
	//第一页
	function first() {
		hideTable();
		page = 1;
		for ( var i = 0; i < pageSize; i++ ) {
			theTable.rows[i].style.display = '';
		}
		showPage();
		preText();
		nextLink();
		lastLink();
	}
	//最后一页
	function last() {
		hideTable();
		page = pageCount();
		currentRow = pageSize * (page - 1);
		for ( var i = currentRow; i < numberRowsInTable; i++ ) {
			theTable.rows[i].style.display = '';
		}
		showPage();
		preLink();
		nextText();
		firstLink();
	}
	function hideTable() {
		for ( var i = 0; i < numberRowsInTable; i++ ) {
			theTable.rows[i].style.display = 'none';
		}
	}
	function showPage() {
		pageNum.innerHTML = page;
	}
	//总共页数
	function pageCount() {
		var count = 0;
		if ( numberRowsInTable % pageSize != 0) count = 1; 
		return parseInt(numberRowsInTable/pageSize) + count;
	}
	//显示链接
	function preLink() { spanPre.innerHTML = "<a href='javascript:pre();'>上一页</a>"; }
	function preText() { spanPre.innerHTML = "上一页"; }
	function nextLink() { spanNext.innerHTML = "<a href='javascript:next();'>下一页</a>"; }
	function nextText() { spanNext.innerHTML = "下一页"; }
	function firstLink() { spanFirst.innerHTML = "<a href='javascript:first();'>首页</a>"; }
	function firstText() { spanFirst.innerHTML = "首页"; }
	function lastLink() { spanLast.innerHTML = "<a href='javascript:last();'>尾页</a>"; }
	function lastText() { spanLast.innerHTML = "尾页"; }
	//隐藏表格
	function hide() {
		for ( var i = pageSize; i<numberRowsInTable; i++ ) {
			theTable.rows[i].style.display = 'none';
		}
		totalPage.innerHTML = pageCount();
		pageNum.innerHTML = '';
		nextLink();
		lastLink();
	}
	hide();
	
	//单双行颜色区分
	function doubleBgColor(Table,Bg1,Bg2) {
	    for (var i=0;i<Table.rows.length;i++){
	    	Table.rows[i].bgColor=i%2?Bg2:Bg1;
	    }
	}
	
	function toCheck() {
		var checkAll = document.getElementById("firstCb");
		var checkboxs = document.getElementsByName("nid");
		var countnum = 0;
		for(var i = 0;i < checkboxs.length;i++){
			if(checkboxs[i].checked){
				countnum++;
			}
		}
		if(countnum == checkboxs.length){
			checkAll.checked = true;
		}else{
			checkAll.checked = false;
		}
	}
	
	window.onload = function() {
		showPage();
		doubleBgColor(document.getElementById("table"),"#DDDDDD","FFFFF");
	    document.getElementById("delSelected").onclick = function(){
	    	var r = confirm("您确定要删除选中信息吗？");
	        if(r==true){
	        	var srr = "";
	        	var inp = document.getElementsByName("nid");
	        	for(var i = 0;i < inp.length;i++){
	        		if(inp[i].checked == true) {	//input的样式是checkbox时就添加到空数组中;
	        			srr += inp[i].value + ",";
	        		}
	        	}
	        	location.href="${pageContext.request.contextPath}/Delete?allnid="+srr+"";
	        }
	    }

	    //获取checkbox
	    document.getElementById("firstCb").onclick = function(){
	        //获取下摆你列表中所有cd
	        var cbs = document.getElementsByName("nid");
	        //遍历
	        for (var i = 0; i < cbs.length; i++) {
	            //设置cbs[]的check状态 = firstCb.checked
	            cbs[i].checked = this.checked;
	        }
	    }
	};
</script>


</html>